<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
require_once("conn.php");

$www = getDomain()."admin/";

$image_file = $_FILES ['imageURL'] ['name'];
if ($image_file != "") {
    $path_parts = pathinfo($image_file);
    $filename = "upload/" . date("YmdHis") . "." . $path_parts ['extension'];
    move_uploaded_file($_FILES ['imageURL'] ['tmp_name'], $filename);
    $imageURL = $www . $filename;
}

$flashcode = checkTrim($_POST['flashcode']);
$url = checkTrim($_POST['url']);
$fp = fopen($url, "r");
if ($fp) {
    
} else {
    echo $url . " 文件不存在！";
}

$version = checkTrim($_POST['version']);
$isModify = $_POST['isModify'];

$db = new DBC();
$is_code_exist = false;
if ($isModify == 1) {
    if ($image_file == "") {
        $sql = "UPDATE t_try SET flashcode = '" . $flashcode . "',name = '" . $name . "',url = '" . $url . "',version='" . $version . "',resoluton='" . $resoluton . "',type = '" . $type . "' WHERE flashcode = " . $flashcode;
    } else {
        $sql = "UPDATE t_try SET flashcode = '" . $flashcode . "',name = '" . $name . "',url = '" . $url . "',imageURL = '" . $imageURL . "',version='" . $version . "',resoluton='" . $resoluton . "',type = '" . $type . "' WHERE productcode = " . $flashcode;
    }
} else {
    $sql = "SELECT flashcode FROM t_try WHERE flashcode= '" . $flashcode . "'";
    $data = $db->fetchData($sql);
    if ($data != null && count($data) > 0) {
        $is_code_exist = true;
    }
    $sql = "INSERT INTO t_try(flashcode,name,url,imageURL,version,requirement,type,resolution,playTimes,createTime) VALUES('" 
    . $flashcode . "','" . $name . "','" . $url . "','" . $imageURL . "','" . $version . "','" . $requirement . "','" . $type . "','" . $resolution 
            . "',0,now())";
}

if ($is_code_exist) {
    $msg = "编号 " . $flashcode . " 已经存在。";
    echo "<script language='javascript'>alert('" . $msg . "'); </script>";
    echo "<script language='javascript'>history.back();</script>";
} else {
    echo $sql;
    $transfer = "fileList.php?menu=apk";
    if ($db->execute($sql)) {
        //success
        //    echo "<script language='javascript'>alert('成功'); </ script>";
        echo "<script language='javascript'>location='" . $transfer . "';</script>";
    } else {
        //failue
        echo "<script language='javascript'>alert('失败'); </script>";
        echo "<script language='javascript'>history.back();</script>";
    }
}

function checkTrim($item) {
    if (isset($item)) {
        $item = trim($item);
    } else {
        $item = "";
    }
    return $item;
}
?>
